package com.efast.dmom.mgmt.controller.master;

import java.util.List;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.mes.ProductExcuteDto;
import com.efast.dmom.mgmt.entity.master.TrBasRouteOperation;
import com.efast.dmom.mgmt.entity.mes.TwBasLot;
import com.efast.dmom.mgmt.service.master.TrBasRouteOperationService;
import com.efast.dmom.mgmt.utils.Assist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/trBasRouteOperation")
public class TrBasRouteOperationController {
	@Autowired
	private TrBasRouteOperationService trBasRouteOperationService;
	
	//获取某一工艺路径下指定工序的完成理由
	@RequestMapping(value = "/getCompleteReasonByOpId")
	public @ResponseBody ResultBean getCompleteReasonByOpId(@RequestBody ProductExcuteDto dto){
		ResultBean result=new ResultBean(true,null);
		TwBasLot lot = dto.getRowData();
		if(lot!=null) {
			Assist assist = new Assist();
			assist.setRequires(Assist.andEq("operation_id", lot.getOperationId()));
			assist.setRequires(Assist.andEq("route", lot.getRoute()));
			List<TrBasRouteOperation> crList = trBasRouteOperationService.selectTrBasRouteOperation(assist);
			if(crList!=null&&crList.size()>0) {
				result.setObject(crList);
			}else {
				if (lot.getIsLastOperation() == 1) {
					result.setSuccess(false);
				} else {
					result.setSuccess(false);
					result.setMessage("请先定义此工艺路径下的指定工序！");
				}
			}
		}else {
			result.setSuccess(false);
			result.setMessage("请选择一个lot！");
		}
		return result;
	}
	
	@RequestMapping(value = "/save")
	public @ResponseBody ResultBean save(@RequestBody TrBasRouteOperation tro){
		ResultBean save = trBasRouteOperationService.save(tro);
		return save;
	}
}
